﻿using System;
using Interfaces;
using Repository;
using Model.Domain_Model;

namespace Presenters
{
    public class ClientAddPresenter
    {
        private IClientAddView view = null;
        private string exception = null;
        private string nameOperation = null;
        private Database db = null;

        public ClientAddPresenter(IClientAddView view)
        {
            this.view = view;
            db = new Database();
        }

        public void ShowFormView(IErrorView view)
        {
            view.nameOperation = "Dodanie klienta";
            view.exception = exception;
            view.ReturnView().ShowDialog();
        }

        public void SuccessDisplay(ISuccesView view)
        {
            view.nameOperation = "Dodanie klienta";
            view.ReturnView().ShowDialog();
        }

        /// <summary>
        /// Zapisuje do bazy danych obiekt typu Clients
        /// </summary>
        public void Save()
        {
            try
            {
                db.newClient(new Client { idClient = 0, nameClient = view.nameClient, surnameClient = view.surnameClient, dateInsert = view.dateInsert, descriptionClient = view.descriptionClient, idGroup=view.idGroup, isProtected=view.isProtected, email=view.email, inventedName=view.inventedName, nameCorporation=view.nameCorporation, phoneNumber=view.phoneNumber });
                view.ShowSuccess();
            }
            catch (Exception ex)
            {
                exception = ex.Message;
                view.ShowError();
            }
        }
    }
}
